<template>
<div class="page">
  <div class="head">收藏请点击上方的 ┅ 添加到我的小程序 <img src="/static/images/hand.png" style="width:24px;height:24px;vertical-align:top;"></img></div>
  <div class="main">
    <div class="title">
      <text>免费抽奖</text>
      <a class="right" href="/pages/guize/main">活动规则</a>
    </div>
    <div class="kuaiA">
      <LuckItem v-for="(luckitem,index) in lucklist" :luckitem="luckitem" :key="index"></LuckItem>
    </div>
    <div class="mt20">瓜分红包</div>
    <div class="kuaiB">
      <LuckBag></LuckBag>
    </div>
    
  </div>
</div>
</template>

<script>
import user from '@/http/user'
import {getlucklist} from '@/http/api'
import LuckItem from '@/components/LuckItem'
import LuckBag from '@/components/LuckBag'

var app = getApp()
export default {
  data () {
    return {
      userInfo: {},
      canIUse: wx.canIUse('button.open-type.getUserInfo'),
      lucklist: []
    }
  },

  components: {
    LuckItem,
    LuckBag
    // LuckList,
    // GoodsItem
  },

  methods: {
    goLogin () {
      const _this = this
      user
        .login()
        .then(res => {
          this.userInfo = res
          app.globalData.userInfo = res
          // app.globalData.token = res.data.token;

          // _this.load()
        })
        .catch(err => {
          _this.$.Tips('登陆失败')
          console.log('登陆失败', err)
        })
    },
    async load () {
      const luckRes = await getlucklist()
      if (luckRes.success) {
        this.lucklist = luckRes.data
      } else {
        console.log('请求错误' + luckRes.message)
      }
    }
  },

  mounted () {
    let query = this.$route.query
    console.log(`收到参数${JSON.stringify(query)}`)
    this.load()
  },
  onShow () {
    let userInfo = wx.getStorageSync('userInfo')
    let token = wx.getStorageSync('token')
    if (userInfo && token) {
      app.globalData.userInfo = userInfo
      app.globalData.token = token
    } else {
      app.globalData.userInfo = null
      app.globalData.token = null
    }
    if (app.globalData.userInfo) {
      this.userInfo = app.globalData.userInfo
    } else {
      this.userInfo = {}
    }
  }
}
</script>

<style lang="scss" scoped>

.page{background:#eee;padding-bottom:20rpx;padding-top:1rpx}
.head{
  background:#fff;padding:20rpx;
  color:rgba(0,0,0,0.66);
  padding-right: 20rpx;
  }
.title{
  display:flex;
 
  .right{margin-left:auto;}
}
.main{margin:20rpx;}

.kuaiB{
  background:#fff;
  margin-top:10rpx;
  border-radius: 5rpx;
  border:1px solid #dddada;}

</style>
